#include <exti.h>
#include <led.h>
#include <delay.h>
#include <key.h>
//#include <GPIO_config.h>
//按键外部中断的配置
//Falling trigger select register
//Rising trigger select register

//KEY0,PC5,FTSR
//KEY1,PA15,FTSR
//WK_UP,PA0,RTSR

void EXTI0_IRQHandler(void)
{
	delay_ms(10);	
	if(WK_UP==1)	
	{
		LED0=!LED0;
		LED1=!LED1;	
	}		 
	EXTI->PR=1<<0;   
}

void EXTI9_5_IRQHandler(void)
{			
	delay_ms(10);   	 
    if(KEY0==0)		
	{
		LED0=!LED0;
	}
 	EXTI->PR=1<<5;    
}

void EXTI15_10_IRQHandler(void)
{			
	delay_ms(10);   		 
    if(KEY1==0)		
	{
		LED1=!LED1;
	}
 	EXTI->PR=1<<15;
}

void EXTI_Init(void)
{
	KEY_Init();
	EXTI->IMR  |= 0x00008021;	//中断屏蔽寄存器，清除对15、5、0的屏蔽
	EXTI->RTSR |= 0x00000001;	//PA0
	EXTI->FTSR |= 0x00008020;	//PA15, PC5
	
	RCC->APB2ENR |= 0x00000001;	//使能AFIO寄存器时钟
	AFIO->EXTICR[0] &= 0xFFFFFFF0;	//PA0
	AFIO->EXTICR[3] &= 0xFFFF0FFF;	//PA15
	AFIO->EXTICR[1] &= 0xFFFFFF0F;
	AFIO->EXTICR[1] |= 0x00000020;	//PC5
	
	MY_NVIC_Init(2,2,EXTI0_IRQn,2);
	MY_NVIC_Init(2,1,EXTI9_5_IRQn,2);
	MY_NVIC_Init(2,0,EXTI15_10_IRQn,2);	
}

